package com.huanletao.dom4j;

import com.huanletao.dom4j.annotation.ElementFormat;
import com.huanletao.dom4j.pojo.Student;

import javax.xml.bind.annotation.XmlRootElement;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * <p>
 * </p>
 * package: com.huanletao.dom4j
 * description:
 * className: App
 * author:  踏雪无痕
 * copyright: Copyright (c) 2022/8/24 14:01
 * since: 1.0.0
 */
public class App {
    public static void main(String[] args) {
        Class<Student> addressClass = Student.class;

        Annotation[] annotations = addressClass.getAnnotations();

        Annotation annotation = annotations[0];
        if (annotation instanceof XmlRootElement) {
            System.out.println("annotation = " + annotation);
        }


        Field[] declaredFields = addressClass.getDeclaredFields();

        for (Field declaredField : declaredFields) {

            Annotation[] fieldAnnotations = declaredField.getAnnotations();
            for (Annotation fieldAnnotation : fieldAnnotations) {

                if (fieldAnnotation instanceof ElementFormat){
                    ElementFormat fieldAnnotation1 = (ElementFormat) fieldAnnotation;
                    String pattern = fieldAnnotation1.pattern();
                    System.out.println("pattern = " + pattern);
                }
            }
        }

    }
}
